<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>流程明细</title>
    <script src="${ctx}/extends/jquery.min.js" type="text/javascript"></script>
    <script src="${ctx}/layui/layui.js"></script>
    <#include "/pubHeadStyle.html">
    <script src="${ctx}/workflowStatic/js/bpmImage.js"></script>
</head>
<body>
<script type="text/html" template>
    <div class="layui-tab " style="margin: 0;overflow: auto;height: 100%;">
        <div id="button" style="padding: 20px"></div>
        <div id="globalFlowNo"></div>
        <#if isExtForm>
        <!--url表单-->
            <iframe id="divExternalForm" style="width: 98%;height:500px;border:none;scrolling:auto"  formUrl="${form}"></iframe>
        <#else>
        <!--在线表单-->
            <div id="form" class="clearfix"></div>
        </#if>
    </div>
</script>

<script>
    layui.config({
        base: serverPath.systemPath + staticPath.formPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'setter', 'element', 'util', 'layer', 'form','commons'], function () {
        var setter = layui.setter
            , commons = layui.commons
            , $ = layui.$
            , util = layui.util
            , layer = layui.layer;
        var procInstId = "${processRun.procInstId}";
        var runId = "${processRun.runId}";
        var modelId = "${processRun.modelId}";
        var businessKey = "${processRun.businessKey}";
        var isCanRedo = "${isCanRedo}";
        var isFirst = "${isFirst}";
        var status = "${processRun.status}";
        var creatorId = "${processRun.creatorId}";
        var isCanRecover = "${isCanRecover}";
        var isCopy = "${isCopy}";
        var prePage = "${prePage}";
        var isFinishedDiver = "${isFinishedDiver}";
        var isPrintForm = "${isPrintForm}";
        var globalFlowNo = "${processRun.globalFlowNo}";
        var isExtForm = "${isExtForm}";
        var form = "${form}";
        init();
        function init() {
            $('#globalFlowNo').html("工单号:" + globalFlowNo);
            if (isExtForm) {
                if (form != null && form != '') {
                    var formUrl= form;
                    $("#divExternalForm").attr('src', formUrl);
                } else {
                    $('#form').html("没有绑定业务表单！");
                }

            } else {
                $('#form').load(form);
            }
            /*if (isFirst || status == 7) {
                $('#button').append(' <a class="layui-btn layui-btn-danger layui-btn-sm" id="delRun">\n' +
                    '            <i class="layui-icon layui-icon-delete"></i>\n' +
                    '            <span>删除</span>\n' +
                    '        </a>');
            }
            if (isCanRecover && prePage == "myRequest") {
                $('#button').append(' <a class="layui-btn layui-btn-sm" lay-event="recover" id="recover">\n' +
                    '            <i class="iconfont iconxiayibudefuben"></i>\n' +
                    '            <span>追回</span>\n' +
                    '        </a>');
            }
            if (isCanRedo && prePage == "myFinishedTask") {
                $('#button').append(' <a class="layui-btn layui-btn-sm" lay-event="cancel" id="cancel">\n' +
                    '            <i class="iconfont iconshangyibu"></i>\n' +
                    '            <span>撤销</span>\n' +
                    '        </a>');

                $('#button').append('<a class="layui-btn layui-btn-sm"  id="urgent">\n' +
                    '            <i class="iconfont icontianxie"></i>\n' +
                    '            <span>催办</span>\n' +
                    '        </a>');
            }
            if (isCopy) {
                $('#button').append('<a class="layui-btn layui-btn-sm" lay-event="copy" id="copy">\n' +
                    '            <i class="layui-icon layui-icon-form"></i>\n' +
                    '            <span>复制</span>\n' +
                    '        </a>');
            }
            if (isFinishedDiver) {
                $('#button').append('<a class="layui-btn layui-btn-sm" lay-event="forward" id="forward">\n' +
                    '            <i class="iconfont iconget"></i>\n' +
                    '            <span>转发</span>\n' +
                    '        </a>');
            }*/
            $('#button').append('<a class="layui-btn layui-btn-sm" lay-event="" id="detail">\n' +
                '            <i class="iconfont iconicon_file"></i>\n' +
                '            <span>运行明细</span>\n' +
                '        </a>');
            $('#button').append('<a class="layui-btn layui-btn-sm flowChart" lay-event="flowChart">\n' +
                '            <i class="layui-icon layui-icon-picture-fine"></i>\n' +
                '            <span >流程图</span>\n' +
                '        </a>');
            $('#button').append('<a class="layui-btn layui-btn-sm" lay-event="" id="taskOpinion">\n' +
                '            <i class="iconfont iconicon_compile"></i>\n' +
                '            <span>审批历史</span>\n' +
                '        </a>');
            /*if (status==2) {
                $('#button').append('<a class="layui-btn layui-btn-sm" lay-event="copyTo" id="copyTo">\n' +
                    '            <i class="iconfont iconjishufuwu"></i>\n' +
                    '            <span>抄送人</span>\n' +
                    '        </a>');
            }*/

        }

        //撤销
        $("#cancel").click(function () {
            parent.layer.open({
                type: 2,
                title: "流程撤销",
                area: ['500px', '300px'],
                content: serverPath.workflowPath + setter.workflowLinkPath + 'processRun/view/recoverDialog?runId=' + runId + '&backToStart=' + 1
            });
        });

        //追回
        $("#recover").click(function () {
            layer.open({
                type: 2,
                title: "流程追回",
                btn:["追回","取消"],
                skin: 'btn-class',
                area: ['450px', '300px'],
                content: serverPath.workflowPath  + setter.workflowLinkPath + 'processRun/view/redoDialog?runId='
                    + runId + '&backToStart=' + 0,
                yes: function (index,layero) {
                    //得到iframe页的窗口对象
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    //执行iframe页的save方法
                    iframeWin.recover(closeInfo);
                }
            });
        });


        //催办
        $("#urgent").click(function () {
            parent.layer.open({
                type: 2,
                title: "催办",
                area: ['500px', '300px'],
                content: serverPath.workflowPath + setter.workflowLinkPath + 'processRun/view/urgeOwner?procInstId=' + procInstId
            });
        });

        //运行明细
        $("#detail").click(function () {
            layer.open({
                type: 2,
                title: "运行明细",
                area: ['80%', '80%'],
                btn: ['关闭'],
                skin: 'btn-close',
                btnAlign: 'c',
                content: serverPath.workflowPath + setter.workflowLinkPath + 'processRun/view/detail?runId=' + runId
            });
        });

        $("#delRun").click(function () {
            layer.confirm("确认要删除该数据吗？", {title: '删除确认'}, function (index) {
                $.ajax({
                    url: serverPath.workflowPath + setter.workflowLinkPath + "processRun/del?runId=" + runId,
                    type: 'DELETE',
                    dataType: 'json',
                    success: function (data) {
                        //成功后的提示
                        if (data.code == 0) {
                            layer.alert("删除成功!",function(index1){
                                layer.close(index1);
                                parent.layer.closeAll(); //如果设定了yes回调，需进行手工关闭
                            });
                        } else {
                            layer.alert("删除失败!");
                        }

                    },
                    error: function (XMLHttpRequest) {
                        layer.alert("请求失败！" + XMLHttpRequest.status);
                    }
                });
            });
        });

        //审批历史
        $("#taskOpinion").click(function () {
            parent.layer.open({
                type: 2,
                title: "审批历史",
                area: ['950px', '585px'],
                content: serverPath.workflowPath + setter.workflowLinkPath + "taskOpinion/view/list?runId=" + runId
            })
        });

        //流程图
        bpmImageShow(procInstId, runId, setter);


        //复制
        $("#copy").click(function () {
            var url = serverPath.workflowPath + setter.workflowLinkPath+"actDefModel/checkVersion";
            $.post(url,{modelId:modelId},function(data){
                if(commons._filterRecord(data)){
                    url = serverPath.workflowPath + setter.workflowLinkPath+"task/view/startFlowForm?modelId="+modelId+'&copyKey='+businessKey;
                    if(data.data == 1){
                        window.open(url);
                    }else{
                        layer.msg('已发布了新版本!<br/>此版本已过期，无法复制!', {time: 2500, icon:5});
                    }
                }else{
                    layer.msg(data.msg, {time: 2500, icon:5});
                }
            },'json');
        });
        //抄送人
        $("#copyTo").click(function () {
            parent.layer.open({
                type: 2,
                title: "抄送人",
                area: ['950px', '620px'],
                content: serverPath.workflowPath + setter.workflowLinkPath + "processCopyTo/view/getList?runId=" + runId
            })
        });

        //转发
        $("#forward").click(function () {
            var oponionDialogIndex = layer.open({
                type: 2,
                title: "转发",
                area: ['950px', '520px'],
                content: serverPath.workflowPath + setter.workflowLinkPath + "processCopyTo/view/forward?runId=" + runId,
                skin: 'btn-class',
                btn: ['确定','取消'],
                btnAlign: 'c',
                yes:function (index,layero) {
                    // var tabDom = layero.children(".layui-layer-content");
                        // var ces = tabDom.find("#forwardDiv form table tbody");
                    //获取iframe的body元素
                    var _tableDom = layer.getChildFrame('body',index).find("#forwardDiv form table");
                    //接收人
                    var userIds  =  _tableDom.find("[name='titleHidden']").val();
                    //消息通知
                    var informTypeElement=_tableDom.find("[name='informType']:checked");
                    var informType = getInformTypes(informTypeElement);
                    //转发意见
                    var opinion  =   _tableDom.find("[name='suggestion']").val();
                    if(userIds.length<=0 ||userIds.length<=0){
                        layer.msg("请选择有效的接收人信息",{icon:5,time:1000});
                        return ;
                    }
                    if(opinion.length<=0){
                        layer.msg("请输入转发意见",{icon:5,time:1000});
                        return ;
                    }
                    $.ajax({
                        url:serverPath.workflowPath + setter.workflowLinkPath+"processCopyTo/saveForward",
                        method: "POST",
                        dataType: 'json',
                        data:{
                            runId:runId,
                            users:userIds,
                            informType:informType,
                            suggestion:opinion
                        },
                        success:function (result) {
                            if (result.code === 0) {
                                layer.alert(result.msg,function(index){
                                    layer.close(index);
                                    layer.close(oponionDialogIndex);
                                });
                            } else {
                                layer.alert(result.msg);
                            }
                        }
                        ,error:function (res) {
                        }
                    });
                },end: function (index) {
                    layer.closeAll('iframe');
                }
            });
        });
        //获取消息类型
        function  getInformTypes(element){
            var informTypes = [];
            element.each(function (index,element) {
                informTypes.push($(element).val());
            });
            return informTypes.toString();
        }

        //关闭弹窗
        function closeInfo() {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        }

    })
</script>
<style>
    #globalFlowNo {
        text-align: right;
        margin-right: 30px;
    }
    .btn-close .layui-layer-btn{
        text-align: center;
    }
    .btn-close .layui-layer-btn a{
        display: inline-block;
        height: 38px;
        line-height: 38px;
        padding: 0 18px;
        background-color: #FF5722;
        color: #fff;
        white-space: nowrap;
        text-align: center;
        font-size: 14px;
        border: none;
        border-radius: 2px;
        cursor: pointer;
    }
    .btn-close .layui-layer-btn0{
        background-color: #FF5722;
    }
</style>
</body>
</html>
<link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
<link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
<style>
    #form .layui-input-block{
        margin-left: 0px;
    }
    .clearfix:after{content:"";display:block;clear:both;height:0;line-height:0;visibility:hidden;}
    .clearfix{zoom:1;}
</style>